{
 "cells": [
  {
   "cell_type": "code",
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2025-10-28T06:00:17.551190Z",
     "start_time": "2025-10-28T06:00:17.548260Z"
    }
   },
   "source": [
    "# 建立数组\n",
    "\n",
    "csv_line = [\n",
    "    \"Alice,25,Engineer,8000\",\n",
    "    \"bob,30,Engineer,75000\",\n",
    "]\n",
    "\n",
    "e = [ {'name':parts[0], 'age':int(parts[1]), 'salary':parts[3]} for line in csv_line for parts in [line.split(',')]\n",
    "      if int(parts[3]) > 8000\n",
    "      ]\n",
    "\n",
    "print(e)\n"
   ],
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[{'name': 'bob', 'age': 30, 'salary': '75000'}]\n"
     ]
    }
   ],
   "execution_count": 6
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-10-28T06:34:04.960284Z",
     "start_time": "2025-10-28T06:34:04.956949Z"
    }
   },
   "cell_type": "code",
   "source": [
    "# 从句子列表中提取长度超过5个字符的单词，并统计词频\n",
    "\n",
    "sentence  = [\n",
    "    \"Python is a powerful programming language\",\n",
    "    \"List comprehension make code more readable\",\n",
    "    \"Functional programming concepts are important\"\n",
    "]\n",
    "\n",
    "\n",
    "# words = [ word for sentence in sentence for word in sentence.split(' ') ]\n",
    "#\n",
    "# from collections import Counter\n",
    "#\n",
    "# wordsCount = Counter(words)\n",
    "#\n",
    "# wordsCount\n",
    "\n",
    "tongji = {}\n",
    "for word in words:\n",
    "    if word in tongji:\n",
    "        tongji[word] = tongji[word]+1\n",
    "    else:\n",
    "        tongji[word] = 1\n",
    "tongji\n",
    "\n"
   ],
   "id": "f0de193f179ab078",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Counter({'programming': 2,\n",
       "         'Python': 1,\n",
       "         'is': 1,\n",
       "         'a': 1,\n",
       "         'powerful': 1,\n",
       "         'language': 1,\n",
       "         'List': 1,\n",
       "         'comprehension': 1,\n",
       "         'make': 1,\n",
       "         'code': 1,\n",
       "         'more': 1,\n",
       "         'readable': 1,\n",
       "         'Functional': 1,\n",
       "         'concepts': 1,\n",
       "         'are': 1,\n",
       "         'important': 1})"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 17
  },
  {
   "metadata": {},
   "cell_type": "markdown",
   "source": "# 函数解包",
   "id": "75e5001a5225409b"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-10-28T06:38:41.170063Z",
     "start_time": "2025-10-28T06:38:41.167818Z"
    }
   },
   "cell_type": "code",
   "source": [
    "def fun(a,b,c):\n",
    "    print(a,b,c)\n",
    "\n",
    "fun(1,2,3)\n",
    "list = [2,3,4]\n",
    "\n",
    "fun(*list)\n"
   ],
   "id": "ae4f3f009d40446d",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 2 3\n",
      "2 3 4\n"
     ]
    }
   ],
   "execution_count": 20
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
